package com.atguigu.classroom.exception;

import com.atguigu.classroom.result.Result;
import io.swagger.annotations.ApiModel;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ApiModel("异常处理类")
@ControllerAdvice
public class GlobalExceptionHandler {
    //全局异常处理
    @ExceptionHandler(Exception.class)
    @ResponseBody//返回json数据
    public Result error(){
        return Result.fail().message("全局de异常");
    }
    //特定异常处理
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody//返回json数据
    public Result arithmeticError(){
        return Result.fail().message("特定异常");
    }
    //自定义异常处理
    @ExceptionHandler(ClassroomException.class)
    @ResponseBody//返回json数据
    public Result ClassroomError(){
        return Result.fail().message("自定义异常");
    }
}
